﻿@{
    ViewBag.Title = "ObjectCallback";
    Layout = "~/Views/Shared/_EaselPage.cshtml";
}

<h2>Object Callback</h2>

<canvas id="canvas" width="1000" height="800" style="border: #008000 solid 1px"></canvas>

<script>

    var stage = new createjs.Stage(document.getElementById('canvas'));
    createjs.Ticker.addEventListener("tick", handleTick);
    createjs.Ticker.setFPS(60);
    function handleTick(e) {
        stage.update();
    }

    var Game = {
        score:0,
        init:function () {
            this.drawButterfly();
        },
        drawButterfly:function () {
            var imgPath = '/Images/butterfly.png';
            var butterfly = new createjs.Bitmap(imgPath);
            stage.addChild(butterfly);
            createjs.Tween.get(butterfly).to({y:100}, 1000).call(this.butterflyGone, [butterfly],this);
        },
        butterflyGone:function (butterfly) {
            stage.removeChild(butterfly);
            this.score += 10;
            this.gameOver();
        },
        gameOver:function () {
            alert('score: ' + this.score);
        }

    }

    window.onload = function () {
        Game.init();
    }

</script>
